package thread.pool;
class MyThread extends Thread{
	public void run(){
		System.out.println("shutDown hook is completed..");
	}
}
public class FctoryMethod {
	public static void main(String[] args) throws Exception {
		Runtime r = Runtime.getRuntime();
		r.addShutdownHook(new MyThread());//The addShutdownHook() method of Runtime class is used to register the thread with the 
		//Virtual Machine
		System.out.println("Now main is sleeping press Ctrl+c..");
		try{
			Thread.sleep(5000);
		}catch(Exception e){

		}/**
The object of Runtime class can be obtained by calling the static factory method getRuntime(). For example:

Runtime r = Runtime.getRuntime();
		 */}
}



// The method that returns the instance of a class is known as factory method.
/*The factory methods are typically implemented as virtual methods, so this pattern is also referred to as 
 * the “Virtual Constructor”. These methods create the objects of the products or target classes.
Read more: http://javarevisited.blogspot.com/2011/12/factory-design-pattern-java-example.html#ixzz3SfBQpz60
 */


